(The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two 您所在的位置:网站首页 office hours were faculty (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two

(The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two

#(The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two| 来源: 网络整理| 查看: 265

** (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the MyDate class defined in Programming Exercise 10.14 to create an object for date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to display the class name and the person’s name. Draw the UML diagram for the classes and implement them. Write a test pro- gram that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods.

** 这里的每个子类要用super的显式去给其父类的变量赋值

package Chapter11; import java.util.*; public class Person11_2 { String name; String address; String phone_number; String email_address; public Person11_2() { } public Person11_2( String n, String a, String p, String e) { name = n; address = a; phone_number = p; email_address = e; } public String toString() { return name + " Person"; } } class Student0 extends Person11_2 { final String status1 = "Freshman"; final String status2 = "Sophomore"; final String status3 = "Junior"; final String status4 = "Senior"; public Student0(String n, String a, String p, String e) { super(n, a, p, e); } public String toString() { return name + " Student"; } } class Employee0 extends Person11_2 { String office; double salary; Date date_hired = new Date(); public Employee0( String n, String a, String p, String e, String o, double s) { super(n, a, p, e); this.office = o; this.salary = s; } public String toString() { return name + " Employee"; } } class Faculty0 extends Employee0 { double work_hour; String rank; public Faculty0( String n, String a, String p, String e, String o, double s, double w, String r) { super(n, a, p, e, o, s); this.work_hour = w; this.rank = r; } public String toString() { return name + " Faculty"; } } class Staff0 extends Employee0 { String title; public Staff0(String n, String a, String p, String e, String o, double s, String t) { super(n, a, p, e, o, s); title = t; } public String toString() { return name + " Staff"; } } package Chapter11; public class Test { public static void main(String[] args) { Person11_2 p = new Person11_2("张三", "北京", "98720349", "[email protected]"); System.out.println(p.toString()); Student0 s = new Student0("李四", "上海", "15153894", "[email protected]"); System.out.println(s.toString()); Employee0 e = new Employee0( "王五", "广州", "5467890", "[email protected]","room101", 399999); System.out.println(e.toString()); Faculty0 f = new Faculty0( "赵六", "深圳", "45678", "[email protected]", "room201",1000000, 8, "leader"); System.out.println(f.toString()); Staff0 sta = new Staff0( "钱七", "9990874", "467547489", "[email protected]", "room001", 29000, "monitor"); System.out.println(sta.toString()); } }

这是测试的结果



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有